package com.ly.hotel.spainterface.jxd.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.common.MyApplication;
import com.ly.hotel.spainterface.jxd.bean.Therapy;
import com.ly.hotel.util.ImageUtil;

import java.util.List;

/**
 * Created by ThinkPad on 2018/3/28.
 */

public class PopTherapListAdapter extends BaseAdapter {

    private Context context;
    private List<Therapy> therapies;
    private int rod  = 0;
    private String isHall;

    public PopTherapListAdapter(Context context, List<Therapy> therapies, String isHall){
        this.context = context;
        this.therapies = therapies;
        rod = context.getResources().getDimensionPixelSize(R.dimen.px6);
        this.isHall = isHall;
    }

    @Override
    public int getCount() {
        return therapies.size();
    }

    @Override
    public Object getItem(int position) {
        return therapies.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        ViewHolder viewHolder = null;
        if(convertView == null){
            view = LayoutInflater.from(context).inflate(R.layout.jxd_pop_gridview_therapy_item,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.therapyImage = view.findViewById(R.id.therapy_image);
            viewHolder.therapyNum = view.findViewById(R.id.therapy_num);
            viewHolder.therapyStatus = view.findViewById(R.id.therapy_status);
            view.setTag(viewHolder);
        }else{
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        final Therapy therapy = therapies.get(position);
        viewHolder.therapyNum.setText(therapy.getArtNo());
        if(therapy.getStatus().equals("空闲")){
            if(therapy.getOnduty().equals("当值")){
                viewHolder.therapyStatus.setText(therapy.getStatus());
            }else{
                viewHolder.therapyStatus.setText(therapy.getOnduty());
            }
        }else {
            viewHolder.therapyStatus.setText(therapy.getStatus());
        }
        String imageUrl = MyApplication.getHostResUrl() + "/upload/interface/technician/pic/" +
                therapy.getArtNo() + ".jpg";
        ImageUtil.displayImage_Round(context,imageUrl,viewHolder.therapyImage,rod);
        return view;
    }

    class ViewHolder{
        ImageView therapyImage;
        TextView therapyNum;
        TextView therapyStatus;
    }
}
